package app;

import java.awt.*;
import java.net.URL;

import javax.swing.*;

/**
 * This class demonstrates how to load an Image from an external file
 */
public class LoadedImage extends Component {
          
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	Image img;

    public void paint(Graphics g) {
        g.drawImage(img, 0, 0, null);
    }

    public LoadedImage(String filePath)  {
       ClassLoader cldr = this.getClass().getClassLoader();
       URL imageURL = cldr.getResource(filePath);
       ImageIcon b = new ImageIcon(imageURL);
	   img = b.getImage();

    }

    public Dimension getPreferredSize() {
        if (img == null) {
             return new Dimension(100,100);
        } else {
           return new Dimension(img.getWidth(null), img.getHeight(null));
       }
    }
}
